package com.cryptoneedle.center.source.service.crud;

import com.cryptoneedle.center.source.entity.constraint.*;
import com.cryptoneedle.center.source.entity.enhance.Dimension;
import com.cryptoneedle.center.source.entity.metadata.*;
import com.cryptoneedle.center.source.repository.constraint.*;
import com.cryptoneedle.center.source.repository.enhance.DimensionRepository;
import com.cryptoneedle.center.source.repository.metadata.*;
import com.cryptoneedle.center.source.service.metadata.CatalogService;
import com.cryptoneedle.center.source.vo.CatalogSaveVo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>description:  </p>
 *
 * @author CryptoNeedle
 * @date 2025-10-23
 */
@Slf4j
@Service
@Transactional
public class SaveDataService {

    @Autowired
    private FoundDataService select;
    @Autowired
    private AddDataService add;
    @Autowired
    private PatchDataService patch;
    @Autowired
    private SaveDataService save;
    @Autowired
    private DeleteDataService delete;

    @Resource
    private ServerRepository serverRepository;
    @Resource
    private CatalogRepository catalogRepository;
    @Resource
    private DatabaseRepository databaseRepository;
    @Resource
    private TableRepository tableRepository;
    @Resource
    private ColumnRepository columnRepository;

    @Resource
    private ConstraintCheckRepository constraintCheckRepository;
    @Resource
    private ConstraintForeignRepository constraintForeignRepository;
    @Resource
    private ConstraintPrimaryRepository constraintPrimaryRepository;
    @Resource
    private ConstraintUniqueRepository constraintUniqueRepository;
    @Resource
    private IndexUniqueRepository indexUniqueRepository;

    @Resource
    private DimensionRepository dimensionRepository;

    @Resource
    private CatalogService catalogService;

    /**
     * ServerRepository
     */
    public void save(Server entity) {
        serverRepository.save(entity);
    }

    public void save(List<Server> list) {
        serverRepository.saveAll(list);
    }

    /**
     * CatalogRepository
     */
    public void save(Catalog entity) {
        catalogRepository.save(entity);
    }

    public void catalogs(List<Catalog> list) {
        catalogRepository.saveAll(list);
    }

    public void save(CatalogSaveVo entity) {
        catalogService.saveVo(entity);
    }

    /**
     * DatabaseRepository
     */
    public void save(Database entity) {
        databaseRepository.save(entity);
    }

    public void databases(List<Database> list) {
        databaseRepository.saveAll(list);
    }

    /**
     * TableRepository
     */
    public void save(Table entity) {
        tableRepository.save(entity);
    }

    public void tables(List<Table> list) {
        tableRepository.saveAll(list);
    }

    /**
     * ColumnRepository
     */
    public void save(Column entity) {
        columnRepository.save(entity);
    }

    public void columns(List<Column> list) {
        columnRepository.saveAll(list);
    }

    /**
     * ConstraintCheckRepository
     */
    public void save(ConstraintCheck entity) {
        constraintCheckRepository.save(entity);
    }

    public void constraintChecks(List<ConstraintCheck> list) {
        constraintCheckRepository.saveAll(list);
    }

    /**
     * ConstraintForeignRepository
     */
    public void save(ConstraintForeign entity) {
        constraintForeignRepository.save(entity);
    }

    public void constraintForeigns(List<ConstraintForeign> list) {
        constraintForeignRepository.saveAll(list);
    }

    /**
     * ConstraintPrimaryRepository
     */
    public void save(ConstraintPrimary entity) {
        constraintPrimaryRepository.save(entity);
    }

    public void constraintPrimarys(List<ConstraintPrimary> list) {
        constraintPrimaryRepository.saveAll(list);
    }

    /**
     * ConstraintUniqueRepository
     */
    public void save(ConstraintUnique entity) {
        constraintUniqueRepository.save(entity);
    }

    public void constraintUniques(List<ConstraintUnique> list) {
        constraintUniqueRepository.saveAll(list);
    }

    /**
     * IndexUniqueRepository
     */
    public void save(IndexUnique entity) {
        indexUniqueRepository.save(entity);
    }

    public void indexUniques(List<IndexUnique> list) {
        indexUniqueRepository.saveAll(list);
    }

    /**
     * DimensionRepository
     */
    public void save(Dimension entity) {
        dimensionRepository.save(entity);
    }

    public void dimensions(List<Dimension> list) {
        dimensionRepository.saveAll(list);
    }

}